#ifndef __SHAPE_H__
#define __SHAPE_H__

#include <iostream>
#include <fstream>
#include <typeinfo>
#include "Point.h"
#include "MyScreen.h"
#include <math.h>

class Circle;
class CRectangle;

using namespace std;

class Shape
{
protected:	
	Point m_point;

	// Movments data members
	double m_dirX, m_dirY;
	double m_sumDirX, m_sumDirY;
	bool m_printWithSplit;
	double m_originalDirX , m_originalDirY;
	int m_timesDirXChanged, m_timesDirYChanged;
	
	bool legalDirXDirY ( double dirX, double dirY) const;
public:
	Shape();

	// seters
	bool setPoint ( int x, int y){m_point.set(x, y); return true;}
	bool setDirection(double dirX, double dirY);
	void addSumDirX (){m_sumDirX += m_dirX; return;}
	void addSumDirY (){m_sumDirY += m_dirY; return;}
	void subtractSumDirX (){m_sumDirX -= m_dirX;}
	void subtractSumDirY (){m_sumDirY -= m_dirY;}
	void add1TimeDirXChanged (){++m_timesDirXChanged;}
	void add1TimeDirYChanged (){++m_timesDirYChanged;}
	void resetTimesChanged (){m_timesDirXChanged = m_timesDirYChanged = 0;}
	void restoreOriginalDir();
	void saveOriginalDir();
	void initSum ();
	void updatePrintWithSplit ();
	void set (Point p1, double dirX, double dirY);

	// geters
	Point getPoint () const {return m_point;}
	int getXPoint () const {return m_point.getx();}
	int getYPoint () const {return m_point.gety();}
	double getDirX () const {return m_dirX;}
	double getDirY ()const {return m_dirY;}
	double getOriginalDirX () const {return m_originalDirX;}
	double getOriginalDirY () const {return m_originalDirY;}
	double getSumDirX () const {return m_sumDirX;}
	double getSumDirY () const {return m_sumDirY;}
	int getTimesDirXChanged () const {return m_timesDirXChanged ;}
	int getTimesDirYChanged () const {return m_timesDirYChanged ;}
	bool getPrintWithSplit () const {return m_printWithSplit;}
	
	virtual bool input()=0;
	virtual bool draw(char frameCh, bool fill=false, MyScreen * scr = NULL, 
					bool split = false)=0;
	virtual bool search(const Point& p1) const =0;
	virtual bool isInBorders() const =0;

	// CollisionsCheck

	virtual void handleCollision (Shape * shape) =0;
	virtual void handleCollision (CRectangle * rec) =0;
	virtual void handleCollision (Circle * cir) =0;
	virtual bool checkStuck (const MyScreen & scr) const =0; 

	//read - write
	virtual bool writeToText (ofstream &file) ;
	void writeTypeId (ofstream &file);
};

#endif

